package com.doc.desensitization.controller;

import com.doc.desensitization.entity.User;
import com.doc.desensitization.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user")
@Slf4j
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @PostMapping("/add")
    public String addUser(User user) {
        log.info("开始添加用户");
        userService.addUser(user);
        log.info("结束添加用户");
        return "添加成功";
    }

    @GetMapping("info/{id}")
    public User getUserInfo(Long id) {
        log.info("开始查询用户信息");
        User user = userService.getUserInfo(id);
        log.info("结束查询用户信息");
        return user;
    }
    @GetMapping("list")
    public List<User> listUser() {
        log.info("开始查询用户列表");
        List<User> list = userService.listUser();
        log.info("结束查询用户列表");
        return list;
    }
}
